package com.huawei.appgallery.appcomment.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import com.huawei.appgallery.appcomment.api.CommentReplyActivityProtocol;
import com.huawei.appgallery.appcomment.api.CommentReplyActivityProtocol.Request;
import com.huawei.appgallery.appcomment.api.IUserCommentListFragmentProtocol;
import com.huawei.appgallery.appcomment.impl.bean.UserReplyInfoCardBean;
import com.huawei.appgallery.appcomment.ui.usercomment.UserReplyInfoCard;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import o.bcb;
import o.bcg.h;
import o.bcg.i;
import o.bcp;
import o.bda;
import o.bdb;
import o.bdj;
import o.bdr;
import o.bdv;
import o.bdz;
import o.bmt;
import o.cdh;
import o.cfw;
import o.cgs;
import o.chz;
import o.cia;
import o.cih;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cks;
import o.cku;
import o.ckv;
import o.cvt;
import o.fjm;
import o.ll;

@FragmentDefine(alias = "UserReplyListFragment", protocol = IUserCommentListFragmentProtocol.class)
public class UserReplyListFragment extends AppListFragment<AppListFragmentProtocol> {
    private static String ॱॱ = "forum|user_detail_review_reply";
    protected String ˊ = "";
    private final byte[] ᐝ = new byte[0];
    private final BroadcastReceiver ﾞ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ UserReplyListFragment ˎ;

        {
            this.ˎ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            if ("com.huawei.appmarket.service.broadcast.Approved.reply".equals(safeIntent.getAction())) {
                Serializable serializableExtra = safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_APPROVED_REPLY");
                if (serializableExtra instanceof o.bdm.e) {
                    this.ˎ.ˊ((o.bdm.e) serializableExtra, this.ˎ.י);
                    if (this.ˎ.ـॱ != null) {
                        this.ˎ.ـॱ.notifyDataSetChanged();
                    }
                }
            } else if ("com.huawei.appmarket.service.broadcast.ReplyDeleted".equals(safeIntent.getAction())) {
                this.ˎ.ॱॱ(safeIntent.getStringExtra("ACTION_PARAM_REPLY_DEL_TYPE_REPLYID"));
            }
        }
    };
    private fjm ﾟ = fjm.ॱ(this);

    class a implements bdz {
        CardBean ˊ;
        final /* synthetic */ UserReplyListFragment ˏ;

        public a(UserReplyListFragment userReplyListFragment, CardBean cardBean) {
            this.ˏ = userReplyListFragment;
            this.ˊ = cardBean;
        }

        public void ˊ() {
            int i = 1;
            if (this.ˊ instanceof UserReplyInfoCardBean) {
                UserReplyInfoCardBean userReplyInfoCardBean = (UserReplyInfoCardBean) this.ˊ;
                synchronized (this.ˏ.ᐝ) {
                    if (userReplyInfoCardBean.ˏ().ॱˊ() == 1) {
                        userReplyInfoCardBean.ˏ().ˏ(0);
                    } else {
                        userReplyInfoCardBean.ˏ().ˏ(1);
                        i = 0;
                    }
                }
                cvt o_bcp = new bcp(userReplyInfoCardBean.ˏ().ॱ(), cdh.ˎ(this.ˏ.ॱˋ()), i);
                userReplyInfoCardBean.ˏ().ˎ(false);
                cfw.ˎ(o_bcp, new bdj(userReplyInfoCardBean.ˏ().ॱ(), this.ˏ.ॱˊ(), i));
            }
        }

        public void ˋ() {
        }
    }

    class c implements OnMenuItemClickListener {
        final /* synthetic */ UserReplyListFragment ˋ;
        String ॱ;

        public c(UserReplyListFragment userReplyListFragment, String str) {
            this.ˋ = userReplyListFragment;
            this.ॱ = str;
        }

        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == o.bcg.e.ʽˊ) {
                this.ˋ.ˊ(this.ॱ);
            }
            return false;
        }
    }

    class e implements bdz {
        final /* synthetic */ UserReplyListFragment ˎ;
        UserReplyInfoCardBean ˏ;

        public e(UserReplyListFragment userReplyListFragment, UserReplyInfoCardBean userReplyInfoCardBean) {
            this.ˎ = userReplyListFragment;
            this.ˏ = userReplyInfoCardBean;
        }

        public void ˊ() {
            this.ˎ.ˊ(this.ˏ);
        }

        public void ˋ() {
        }
    }

    public static UserReplyListFragment ˎ(String str) {
        UserReplyListFragment userReplyListFragment = new UserReplyListFragment();
        Bundle bundle = new Bundle();
        bundle.putString("app_reply_list_request_accountid", str);
        userReplyListFragment.ʼ(bundle);
        return userReplyListFragment;
    }

    public void ˏ(Bundle bundle) {
        ˋॱ(102010);
        Bundle ˊॱ = ˊॱ();
        if (ˊॱ != null) {
            this.ˊ = ˊॱ.getString("app_reply_list_request_accountid");
        }
        IUserCommentListFragmentProtocol iUserCommentListFragmentProtocol = (IUserCommentListFragmentProtocol) this.ﾟ.ॱ();
        if (iUserCommentListFragmentProtocol != null && TextUtils.isEmpty(this.ˊ)) {
            this.ˊ = iUserCommentListFragmentProtocol.getUserId();
        }
        super.ˏ(bundle);
        this.ˏͺ = 5;
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Approved.reply");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.ReplyDeleted");
        ll.ˏ(ॱˋ()).ˏ(this.ﾞ, intentFilter);
        return super.ˋ(layoutInflater, viewGroup, bundle);
    }

    public void ˊ(o.bdm.e eVar, cia o_cia) {
        if (o_cia != null) {
            for (chz o_chz : o_cia.ʻॱ()) {
                if (o_chz != null && o_chz.ˎ.size() > 0) {
                    for (BaseCardBean baseCardBean : o_chz.ˎ) {
                        if (baseCardBean instanceof UserReplyInfoCardBean) {
                            UserReplyInfoCardBean userReplyInfoCardBean = (UserReplyInfoCardBean) baseCardBean;
                            if (userReplyInfoCardBean.ˏ().ॱ().equals(eVar.ॱ())) {
                                if (!userReplyInfoCardBean.ˏ().ˏॱ()) {
                                    int ˋॱ = userReplyInfoCardBean.ˏ().ˋॱ() + eVar.ˋ();
                                    if (ˋॱ < 0) {
                                        ˋॱ = 0;
                                    }
                                    userReplyInfoCardBean.ˏ().ˊ(ˋॱ);
                                }
                                userReplyInfoCardBean.ˏ().ˎ(true);
                                userReplyInfoCardBean.ˏ().ˏ(eVar.ॱॱ());
                                o_cia.ͺ();
                            }
                        }
                    }
                }
            }
        }
    }

    public void ᐝ() {
        super.ᐝ();
        ll.ˏ(ॱˋ()).ˋ(this.ﾞ);
    }

    public void ॱ(NodataWarnLayout nodataWarnLayout) {
        if (nodataWarnLayout != null) {
            nodataWarnLayout.setWarnImage(o.bcg.c.ˊ);
            nodataWarnLayout.setWarnTextOne(h.ـॱ);
            nodataWarnLayout.setViewVisible(com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout.e.WARN_BTN, 8);
            nodataWarnLayout.setViewVisible(com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout.e.WARN_TEXTTWO, 8);
        }
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(ॱॱ);
        if (!TextUtils.isEmpty(this.ˊ)) {
            stringBuilder.append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˊ);
        }
        list.add(new bda(stringBuilder.toString(), this.ˏ));
    }

    public void ˏ(int i, cih o_cih) {
        if (o_cih != null) {
            CardBean ˌ = o_cih.ˌ();
            if (i == 1006) {
                if (!bmt.ˊ(ॱˋ())) {
                    ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
                    return;
                } else if (ˌ instanceof UserReplyInfoCardBean) {
                    ˋ(ˌ);
                    return;
                }
            } else if (i == 1007) {
                new bdr(ॱˋ(), new a(this, ˌ)).ˎ();
                return;
            } else if (i == 1008 && (ˌ instanceof UserReplyInfoCardBean)) {
                ˎ(((UserReplyInfoCard) o_cih).ॱॱ(), ((UserReplyInfoCardBean) ˌ).ˏ().ॱ());
                return;
            }
            super.ˏ(i, o_cih);
        }
    }

    private void ˎ(View view, String str) {
        if (view != null) {
            PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
            popupMenu.getMenuInflater().inflate(i.ˎ, popupMenu.getMenu());
            popupMenu.setOnMenuItemClickListener(new c(this, str));
            popupMenu.show();
        }
    }

    private void ˊ(final String str) {
        Context ॱˋ = ॱˋ();
        if (ॱˋ != null) {
            CharSequence string = ॱˋ.getString(h.ᐧ);
            cku ˋ = cku.ˋ(null, ॱˋ.getString(h.ͺˏ));
            ˋ.ˎ(ॱˋ);
            ˋ.ॱ(-1, string);
            ˋ.ॱ(new cks(this) {
                final /* synthetic */ UserReplyListFragment ॱ;

                public void enableNetworking() {
                    this.ॱ.ॱ(str);
                }

                public void upgrade() {
                }

                public void ˋ() {
                }
            });
        }
    }

    private void ॱ(String str) {
        Context ʻॱ = AbstractBaseActivity.ʻॱ();
        if (ʻॱ == null) {
            bcb.ˋ.ˋ("UserReplyListFragment", "current Activity is null");
        } else if (bmt.ˊ(ʻॱ)) {
            cvt o_bdb = new bdb(str);
            o_bdb.setServiceType_(cdh.ˎ(ʻॱ));
            cfw.ˎ(o_bdb, new bdv(str, ʻॱ));
        } else {
            ckv.ˎ(ʻॱ.getString(h.ᐝʽ), 0);
        }
    }

    private void ˋ(CardBean cardBean) {
        ˎ((UserReplyInfoCardBean) cardBean);
    }

    private void ˎ(UserReplyInfoCardBean userReplyInfoCardBean) {
        new bdr(ॱˋ(), new e(this, userReplyInfoCardBean)).ˎ();
    }

    private void ˊ(UserReplyInfoCardBean userReplyInfoCardBean) {
        cjo commentReplyActivityProtocol = new CommentReplyActivityProtocol();
        Request request = new Request();
        request.ˎ(true);
        request.ˊ(userReplyInfoCardBean.ˏ().ʼ().ॱॱ());
        request.ˏ(userReplyInfoCardBean.ˏ().ʼ().ʽ());
        request.ˊ(userReplyInfoCardBean.ˏ().ॱˊ());
        commentReplyActivityProtocol.ˏ(request);
        cjk.ˎ().ˋ(ॱˋ(), new cjm("appdetailreply.activity", commentReplyActivityProtocol));
    }

    private void ॱॱ(String str) {
        if (this.י != null && !TextUtils.isEmpty(str)) {
            for (chz o_chz : this.י.ʻॱ()) {
                if (!(o_chz == null || cgs.ˋ(o_chz.ˎ))) {
                    List list = o_chz.ˎ;
                    Iterator it = list.iterator();
                    while (it.hasNext()) {
                        BaseCardBean baseCardBean = (BaseCardBean) it.next();
                        if ((baseCardBean instanceof UserReplyInfoCardBean) && str.equals(((UserReplyInfoCardBean) baseCardBean).ˏ().ॱ())) {
                            it.remove();
                            break;
                        }
                    }
                    this.י.ͺ();
                    if (list.size() == 0) {
                        ˋॱ(false);
                    }
                }
            }
        }
    }
}
